const express = require('express');
const router = express.Router();

/**
 * CORS 测试路由
 * GET /api/cors-test
 */
router.get('/', (req, res) => {
  res.json({
    success: true,
    message: 'CORS 测试成功',
    data: {
      timestamp: new Date().toISOString(),
      origin: req.headers.origin || 'unknown',
      userAgent: req.headers['user-agent'],
      method: req.method,
      headers: req.headers
    }
  });
});

/**
 * POST 请求测试
 * POST /api/cors-test
 */
router.post('/', (req, res) => {
  res.json({
    success: true,
    message: 'CORS POST 测试成功',
    data: {
      timestamp: new Date().toISOString(),
      body: req.body,
      origin: req.headers.origin || 'unknown'
    }
  });
});

/**
 * PUT 请求测试
 * PUT /api/cors-test
 */
router.put('/', (req, res) => {
  res.json({
    success: true,
    message: 'CORS PUT 测试成功',
    data: {
      timestamp: new Date().toISOString(),
      body: req.body,
      origin: req.headers.origin || 'unknown'
    }
  });
});

/**
 * DELETE 请求测试
 * DELETE /api/cors-test
 */
router.delete('/', (req, res) => {
  res.json({
    success: true,
    message: 'CORS DELETE 测试成功',
    data: {
      timestamp: new Date().toISOString(),
      origin: req.headers.origin || 'unknown'
    }
  });
});

module.exports = router; 